﻿CREATE PROCEDURE [ServiceEngine].[UpdateBindingElement]
	@Name nvarchar(400),
	@Description ntext = null,
	@ElementConfig xml,
	@ElementType smallint,
	@ID uniqueidentifier
AS
BEGIN
	DECLARE @ErrorMessage NVARCHAR(4000);
	DECLARE @ErrorSeverity INT;
	DECLARE @ErrorState INT;
	SET NOCOUNT ON;

	BEGIN TRY
		BEGIN TRANSACTION

		UPDATE	ServiceEngine.BindingElements
		SET		ElementConfig = @ElementConfig,
				ElementType = @ElementType
		WHERE	BindingElementID = @ID

		UPDATE	ServiceEngine.Names
		SET		EntityName = @Name,
				EntityDescription = @Description
		WHERE	EntityID = @ID and EntityTypeID = 17

		COMMIT TRANSACTION
	END TRY
	BEGIN CATCH
		SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();

		IF XACT_STATE() <> 0 ROLLBACK TRANSACTION;

		RAISERROR (@ErrorMessage, 
				   @ErrorSeverity,
				   1);
	END CATCH
END


